<?php
namespace app\admin\controller;

use think\Controller;
use Common\Controller\BaseController;
use think\Request;
use think\Session;


class Save extends Controller
{
    public function index(){
        return $this->fetch();
    }
    //管理员修改密码开始
    public function save_pwd(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        return $this->fetch();
    }
    public function save_pwdupdata(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }

        if(!$_POST){
            echo "<script>alert('提交不能为空');location.href='save_pwd';</script>";

        }
        $name['name'] = session('user.name');

        $orpassword['orpassword'] = md5(md5(trim($_POST['orpassword'])));
        $password['password'] = md5(md5(trim($_POST['password'])));
        $repassword['repassword'] = md5(md5(trim($_POST['repassword'])));
        $res = db('admin')->where($name)->find();

        if($res['password'] != $orpassword['orpassword']){
            return ['code'=>1,'msg'=>'原密码不正确'];
        }
        //dump($name);exit;
        $sql = db('admin')->where($name)->update($password);
        if($sql){
            return ['code'=>2,'msg'=>'修改成功'];
            //echo "<script>alert('修改成功');location.href='save_pwd';</script>";
        }else{
            return ['code'=>3,'msg'=>'修改失败'];
            //echo "<script>alert('修改失败');location.href='save_pwd';</script>";
        }
    }
//管理员修改密码结束

}